﻿@model VacationsRequest.Models.VacationTimeSpan
@{
    ViewBag.Title = "Details";
}
<script type="text/javascript">

    var d = new Date();
    var curr_date = d.getDate();
    var curr_month = d.getMonth() + 2; //Months are zero based
    var curr_year = d.getFullYear();
    $(document).ready(function () {
        $.ajax({
            type: "GET",
            contentType: "application/json",
            data: "{}",
            url: '/VacationDays/HolidaysList',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) {

                holidays = data;

                $('#date3').DatePicker({
                    flat: true,
                    date: [],
                    current: curr_year + "-" + curr_month + "-" + curr_date,
                    calendars: 3,
                    mode: 'range',
                    onRender: function (date) {
                        var dateStr = date.getFullYear() + "" + (date.getMonth() + 1) + "" + date.getDate();
                        return {
                            
                            className: ($.inArray(dateStr, holidays) != -1) ? 'holiday' : false
                        }
                    },
                    starts: 1,
                    onChange: function (formated, dates) {
                        $('.fromDate').val(formated[0]);
                        $('.toDate').val(formated[1]);
                    }
                });
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                debugger;
            }
        });

    });

</script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<h2>
    Details</h2>
<fieldset>
    <legend>Employee</legend>
    <div style="display: table; width: 100%">
        <div style="display: table-row">
            <div style="display: table-cell">
                <div class="display-label">
                    Name</div>
                <div class="display-field">
                    @ViewBag.CurrentEmployee.FirstName @ViewBag.CurrentEmployee.FirstLastName @ViewBag.CurrentEmployee.SecondLastName
                </div>
            </div>
            <div style="display: table-cell">
                <div class="display-label">
                    Team</div>
                <div class="display-field">
                    @ViewBag.TeamName
                </div>
            </div>
            <div style="display: table-cell">
                <div class="display-label">
                    Position</div>
                <div class="display-field">
                    @ViewBag.PositionName
                </div>
            </div>
            <div style="display: table-cell">
                <div class="display-label">
                    Manager</div>
                <div class="display-field">
                    @ViewBag.ManagerName
                </div>
            </div>
        </div>
        <div style="display: table-row">
            <div style="display: table-cell">
                <div class="display-label">
                    Total Vacations</div>
                <div class="display-field">
                    @ViewBag.TotalVacations
                </div>
            </div>
            <div style="display: table-cell">
                <div class="display-label">
                    Remaining Vacations</div>
                <div class="display-field">
                    @ViewBag.RemainingDays
                </div>
            </div>
            <div style="display: table-cell">
                <div class="display-label">
                    Taken Vacations</div>
                <div class="display-field">
                    @ViewBag.TakenDays
                </div>
            </div>
            <div style="display: table-cell">
                <div class="display-label">
                    Reserved Vacations</div>
                <div class="display-field">
                    @ViewBag.ReservedDays
                </div>
            </div>
        </div>
    </div>
</fieldset>
<p>
    @Html.ActionLink("Vacations Report", "VacationsReportByEmployee", "Employees", new { id = ViewBag.CurrentEmployee.ID }, new { target = "_blank" })
</p>
@using (Html.BeginForm())
{  
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>Add Vacations</legend>
        <div style="display: table; width: 100%">
            <div style="display: table-row">
                <div style="display: table-cell">
                    <div id="date3">
                    </div>
                </div>
            </div>
            <div style="display: table-row">
                <div style="display: table-cell">
                    <div class="display-label">
                        Comment</div>
                    <div class="display-field">
                        @Html.EditorFor(model => model.Comment)
                        @Html.HiddenFor(model => model.FromDate, new { @class = "fromDate" })
                        @Html.HiddenFor(model => model.ToDate, new { @class = "toDate" })
                        <div>
                            @Html.ValidationMessageFor(model => model.Comment)</div>
                    </div>
                </div>
            </div>
            <div style="display: table-cell">
                <div style="display: table-cell">
                    <div class="display-label">
                    </div>
                    <div class="display-field">
                        <input type="submit" value="Save" />
                    </div>
                </div>
            </div>
        </div>
    </fieldset>
}
<table border="0" cellpadding="0" cellspacing="0" style="width: 100%;">
    <tr>
        <th>
            Taken
        </th>
        <th>
            Pending
        </th>
    </tr>
    <tr>
        <td style="vertical-align: top;">
            <table style="width: 100%;">
                <tr>
                    <th>
                        Date
                    </th>
                    <th>
                        Comment
                    </th>
                    <th />
                </tr>
                @foreach (VacationsRequest.Models.VacationDay item in ViewBag.VacationsListTaken)
                {
                    <tr @Html.UsedDateStyle(item.Date)>
                        <td style="text-align: center">
                            @item.Date.ToShortDateString()
                        </td>
                        <td>
                            @item.Comment
                        </td>
                        <td>
                            @if (item.Date <= DateTime.Now)
                            {
                                if (User.IsInRole("Administrator"))
                                {
                                @Html.ActionLink("Delete", "Delete", new { id = item.ID }, new { onclick = "return confirm('Are you sure you wish to delete this vacation day?');" })
                                }
                            }
                            else
                            {
                                @Html.ActionLink("Delete", "Delete", new { id = item.ID }, new { onclick = "return confirm('Are you sure you wish to delete this vacation day?');" })
                            }
                        </td>
                    </tr>
                }
                <tfoot>
                    <tr>
                        <td colspan='2'>
                            <div>
                                Page @(ViewBag.VacationsListTaken.PageCount < ViewBag.VacationsListTaken.PageNumber ? 0 : ViewBag.VacationsListTaken.PageNumber)
                                of @ViewBag.VacationsListTaken.PageCount &nbsp;&nbsp;&nbsp;
                                @if (ViewBag.VacationsListTaken.HasPreviousPage)
                                {
                                    @Html.ActionLink("<<", "Details", new { page = 1, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter })
                                    @Html.Raw(" ");
                                    @Html.ActionLink("< Prev", "Details", new { page = ViewBag.VacationsListTaken.PageNumber - 1 })
                                }
                                else
                                {
                                    @:<<
        @Html.Raw(" ");
                                    @:< Prev
                                                                                                                                                                                                                        }
                                &nbsp;&nbsp;&nbsp;
                                @if (ViewBag.VacationsListTaken.HasNextPage)
                                {
                                    @Html.ActionLink("Next >", "Details", new { page = ViewBag.VacationsListTaken.PageNumber + 1 })
                                    @Html.Raw(" ");
                                    @Html.ActionLink(">>", "Details", new { page = ViewBag.VacationsListTaken.PageCount })
                                }
                                else
                                {
                                    @:Next >
        @Html.Raw(" ")
                                    @:>>
                                                                                                                                                                                                                        }
                            </div>
                        </td>
                    </tr>
                </tfoot>
            </table>
        </td>
        <td style="vertical-align: top;">
            <table style="width: 100%;">
                <tr>
                    <th>
                        Date
                    </th>
                    <th>
                        Comment
                    </th>
                    <th />
                </tr>
                @foreach (VacationsRequest.Models.VacationDay item in ViewBag.VacationsLisReserved)
                {
                    <tr @Html.UsedDateStyle(item.Date)>
                        <td style="text-align: center">
                            @item.Date.ToShortDateString()
                        </td>
                        <td>
                            @item.Comment
                        </td>
                        <td>
                            @if (item.Date <= DateTime.Now)
                            {
                                if (User.IsInRole("Administrator"))
                                {
                                @Html.ActionLink("Delete", "Delete", new { id = item.ID }, new { onclick = "return confirm('Are you sure you wish to delete this vacation day?');" })
                                }
                            }
                            else
                            {
                                @Html.ActionLink("Delete", "Delete", new { id = item.ID }, new { onclick = "return confirm('Are you sure you wish to delete this vacation day?');" })
                            }
                        </td>
                    </tr>
                }
                <tfoot>
                    <tr>
                        <td colspan='2'>
                            <div>
                                Page @(ViewBag.VacationsLisReserved.PageCount < ViewBag.VacationsLisReserved.PageNumber ? 0 : ViewBag.VacationsLisReserved.PageNumber)
                                of @ViewBag.VacationsLisReserved.PageCount &nbsp;&nbsp;&nbsp;
                                @if (ViewBag.VacationsLisReserved.HasPreviousPage)
                                {
                                    @Html.ActionLink("<<", "Details", new { page2 = 1 })
                                    @Html.Raw(" ");
                                    @Html.ActionLink("< Prev", "Details", new { page2 = ViewBag.VacationsLisReserved.PageNumber - 1 })
                                }
                                else
                                {
                                    @:<<
        @Html.Raw(" ");
                                    @:< Prev
                                                                                                                                                                                                                                                            }
                                &nbsp;&nbsp;&nbsp;
                                @if (ViewBag.VacationsLisReserved.HasNextPage)
                                {
                                    @Html.ActionLink("Next >", "Details", new { page2 = ViewBag.VacationsLisReserved.PageNumber + 1 })
                                    @Html.Raw(" ");
                                    @Html.ActionLink(">>", "Details", new { page2 = ViewBag.VacationsLisReserved.PageCount })
                                }
                                else
                                {
                                    @:Next >
        @Html.Raw(" ")
                                    @:>>
                                                                                                                                                                                                                                                            }
                            </div>
                        </td>
                    </tr>
                </tfoot>
            </table>
        </td>
    </tr>
</table>
